package DAO;

import Interfaces.ILogin_Dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Login_Dao implements ILogin_Dao {

    @Override
    public boolean userLogin(String Name, String Pass) throws IllegalArgumentException {
        boolean user;
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement pst = null;
        try {
            conn = javaconnect.connectDB();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Login_Dao.class.getName()).log(Level.SEVERE, null, ex);
        }

        String query = "SELECT * FROM user WHERE username=? and password=?";
        try {
            pst = conn.prepareStatement(query);
            pst.setString(1, Name);
            pst.setString(2, Pass);
            rs = pst.executeQuery();

            if (rs.next()) {
                user = true;
            } else {
                user = false;
            }

            pst.close();
            conn.close();

        } catch (SQLException e) {
            throw new IllegalArgumentException("Error in Login_Dao ");
        }
        return user;
    }
}
